//控制层
app.controller('advertisingCategoryController' ,function($scope,$controller,advertisingCategoryService){

    $controller('commonController',{$scope:$scope});//继承

    //读取列表数据绑定到表单中
    $scope.findAll=function(){
        advertisingCategoryService.findAll().success(
            function(response){
                $scope.list=response;
            }
        );
    }
    $scope.searchEntity={};//定义搜索对象

    //搜索
    $scope.search=function(page,rows){
        advertisingCategoryService.search(page,rows,$scope.searchEntity).success(
            function(response){
                $scope.list=response.result;
                $scope.paginationConf.totalItems=response.total;//更新总记录数
            }
        );
    }

    //查询实体
    $scope.findOne=function(id){
        advertisingCategoryService.findOne(id).success(
            function(response){
                $scope.entity= response;
            }
        );
    }

    //保存
    $scope.save=function(){
        var serviceObject;//服务层对象
        if($scope.entity.id!=null){//如果有ID
            serviceObject=advertisingCategoryService.update( $scope.entity ); //修改
        }else{
            serviceObject=advertisingCategoryService.add( $scope.entity  );//增加
        }
        serviceObject.success(
            function(response){
                if(200==response.code){
                    //重新查询
                    $scope.reloadList();//重新加载
                }else{
                    alert(response.message);
                }
            }
        );
    }


    //批量删除
    $scope.delete=function(){
        //获取选中的复选框
        advertisingCategoryService.delete( $scope.selected ).success(
            function(response){
                if(200==response.code){
                    $scope.reloadList();//刷新列表
                    $scope.selected=[];
                }
            }
        );
    }


});
